package com.csi.bumblebee.controller;

import com.csi.bumblebee.domain.dictionary.Major;
import com.csi.bumblebee.domain.dictionary.School;
import com.csi.bumblebee.domain.util.MyResult;
import com.csi.bumblebee.domain.util.StateCode;
import com.csi.bumblebee.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 孙伟俊
 */
@RestController
@RequestMapping("/major")
public class MajorController {

    @Autowired
    private MajorService majorService;

    @GetMapping("/")
    public MyResult<List<Major>> list(){
        MyResult<List<Major>> myResult = new MyResult<>();

        List<Major> list = majorService.list();
        if (list != null){
            myResult.setData(list);
            myResult.setMessage("查询成功");
            myResult.setCode(StateCode.FIND_SUCCESS);
        }else {
            myResult.setCode(StateCode.FIND_FAILURE);
            myResult.setMessage("查询失败");
        }

        return myResult;
    }

    @GetMapping("/list/tree")
    public MyResult<List<Major>> listMajorTree(){
        MyResult<List<Major>> myResult = new MyResult<>();

        List<Major> list = majorService.listMajorTree();
        if (list != null){
            myResult.setData(list);
            myResult.setMessage("查询成功");
            myResult.setCode(StateCode.FIND_SUCCESS);
            System.out.println("++++++++++++++++++++++++++成功");
            for (Major major : list) {
                System.out.println(major.getMajorName());
            }
        }else {
            myResult.setCode(StateCode.FIND_FAILURE);
            myResult.setMessage("查询失败");
        }

        return myResult;
    }

}
